Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.KS_RecorderManager = undefined;
var $2UIHelp = require("UIHelp");
var exp_KS_RecorderManager = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.mediaRecorder = null;
    this.videoPath = null;
    this.tage = "";
    this.shared = false;
    this.recordering = false;
  }
  return babel_createClass(_ctor, [{
    key: "start",
    value: function start() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 280;
      if (window.kwaigame) {
        console.log("KS_RecorderManager 录频开始");
        this.shared = false;
        this.tage = "start";
        this.mediaRecorder.start();
      }
    }
  }, {
    key: "initGameRecorderManager",
    value: function initGameRecorderManager() {
      var _this50 = this;
      if (window.kwaigame) {
        this.mediaRecorder = window.kwaigame.createMediaRecorder();
        if (null === this.mediaRecorder) {
          console.log("返回 null 时表示当前 APP 版本不支持录屏");
        } else {
          this.mediaRecorder.onStart(function () {
            _this50.recordering = true;
            console.log("KS_RecorderManager onStart");
          }), this.mediaRecorder.onStop(function (e) {
            _this50.recordering = false;
            _this50.videoPath = e.videoID;
            console.log("录频停止成功 ".concat(JSON.stringify(e), " "));
          }), this.mediaRecorder.onError(function (e) {
            console.log("录频过程中发生错误 ".concat(JSON.stringify(e), " "));
          });
        }
      }
    }
  }, {
    key: "shareAppMessage",
    value: function shareAppMessage(e, t) {
      var _this51 = this;
      if (window.kwaigame || !this.mediaRecorder) {
        if (1 != this.shared) {
          console.log("开始分享", this.videoPath);
          this.mediaRecorder.publishVideo({
            video: this.videoPath,
            callback(t) {
              if (null != t && null != t) {
                console.log("分享录屏失败: " + JSON.stringify(t));
                return void (e && e(false));
              }
              _this51.shared = true;
              console.log("分享视频成功", t);
              e && e(true);
            }
          });
        } else {
          $2UIHelp.UIHelp.showTip("此视频已经分享,不能重复分享！");
        }
      } else {
        e && e(true);
      }
    }
  }, {
    key: "navigateToVideoView",
    value: function navigateToVideoView(e) {
      window.kwaigame && window.kwaigame.navigateToVideoView({
        videoId: e,
        success() {
          console.log("done");
        },
        fail(e) {
          1006 === e.errCode && window.kwaigame.showToast({
            title: "something wrong with your network"
          });
        }
      });
    }
  }, {
    key: "request",
    value: function request(e, t) {
      window.kwaigame.request({
        url: "https://gate.snssdk.com/developer/api/get_video_info",
        method: "POST",
        data: {
          alias_ids: e
        },
        success(e) {
          t && t(e);
        },
        fail(e) {
          t && t(e);
        }
      });
    }
  }, {
    key: "shareVideo",
    value: function shareVideo(e) {
      if (window.kwaigame) {
        1 != this.recordering && "" != this.videoPath && window.kwaigame.shareVideo({
          videoPath: "".concat(this.videoPath),
          success() {
            console.log("分享成功！");
            e && e(true);
          },
          fail(t) {
            console.log("分享失败！");
            e && e(false);
          }
        });
      } else {
        e && e(true);
      }
    }
  }, {
    key: "stop",
    value: function stop() {
      if (window.kwaigame) {
        console.log("ks结束录制");
        "pause" == this.tage && this.resume();
        this.tage = "stop";
        this.mediaRecorder.stop();
      }
    }
  }, {
    key: "pause",
    value: function pause() {
      if (window.kwaigame) {
        console.log("ks暂停录制");
        this.tage = "pause";
        this.mediaRecorder.pause();
      }
    }
  }, {
    key: "resume",
    value: function resume() {
      if (window.kwaigame) {
        console.log("ks恢复录制");
        this.tage = "resume";
        this.mediaRecorder.resume();
      }
    }
  }], [{
    key: "getInstance",
    value: function getInstance() {
      if (null == this._instance) {
        this._instance = new _ctor();
        this._instance.initGameRecorderManager();
      }
      return this._instance;
    }
  }]);
}();
exports.KS_RecorderManager = exp_KS_RecorderManager;
exp_KS_RecorderManager._instance = null;